home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Networking & Communications / Serial NB Sample Driver / Test / ARDriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  4.7 KB  |  208 lines  |  [TEXT/MPS ]

  1. /********************************************************************************/
  2. /*                                                                                */
  3. /*        ARDriver.c - A/ROSE driver PB calls.                                    */
  4. /*                                                                                */
  5. /*        Richard W. Mincher.        February 20, 1990.                                */
  6. /*                                                                                */
  7. /*        Copyright © 1990, Apple Computer, Inc.  All rights reserved.            */
  8. /*                                                                                */
  9. /********************************************************************************/
  10.  
  11.  
  12. #include    "Types.h"
  13. #include    "Files.h"
  14. #include    "Memory.h"
  15. #include    "Resources.h"
  16.  
  17. #include    "AROSE.h"
  18. #include    "os.h"
  19.  
  20. #include    "ARDriver.h"
  21. #include    "ARTask.h"
  22.  
  23. void    RxComplete(message *m);
  24.  
  25. pascal OSErr
  26. ARPBControl(ParmBlkPtr pb, short async)
  27. {
  28.     AROSEmessage    *m;
  29.     struct globals    *g;
  30.     
  31. #ifdef    DEBUG
  32.     Debugger();
  33. #endif    DEBUG
  34.     g = (struct globals *)(((pb->cntrlParam.ioCRefNum & 0xF000) << 8) +
  35.         (pb->cntrlParam.ioCRefNum & 0x0180) + 0x200);
  36.     SetMyTid( g->hisTid );
  37.     m = GetMsg();
  38.     m->mTo = (tid_type)(g->myTid);
  39.     m->mCode = SNBControl;
  40.     m->mSData[0] = (unsigned long)pb;
  41.     m->mDataPtr = StripAddress((Ptr)(&(pb->cntrlParam.csCode)));
  42.     m->mDataSize = 24;
  43.     pb->cntrlParam.ioResult = 1;
  44.     Send( m );
  45.     if (!async)
  46.     {
  47.         while(pb->cntrlParam.ioResult > 0)
  48.             PushAIPC();
  49.         return (pb->cntrlParam.ioResult);
  50.     }
  51.     else
  52.         return (noErr);
  53. }
  54.  
  55. pascal OSErr
  56. ARPBKillIO(ParmBlkPtr pb, short async)
  57. {
  58.     pb->cntrlParam.csCode = 1;
  59.     return (ARPBControl(pb, async));
  60. }
  61.  
  62. //pascal OSErr
  63. //ARPBStatus(ParmBlkPtr pb, short async)
  64. //{
  65. //    AROSEmessage    *m;
  66. //    long            *addr;
  67. //    
  68. //#ifdef    DEBUG
  69. //    Debugger();
  70. //#endif    DEBUG
  71. //    addr = (long *)(((pb->cntrlParam.ioCRefNum & 0xFF00) << 8) +
  72. //        (pb->cntrlParam.ioCRefNum & 0xFF) + 0x700);
  73. //    SetMyTid(addr[1]);
  74. //    m = GetMsg();
  75. //    m->mTo = (tid_type)(addr[0]);
  76. //    m->mFrom = (tid_type)(addr[1]);
  77. //    m->mCode = SNBStatus;
  78. //    m->mSData[0] = (unsigned long)pb;
  79. //    m->mDataPtr = StripAddress((Ptr)(&(pb->cntrlParam.csCode)));
  80. //    m->mDataSize = 24;
  81. //    pb->cntrlParam.ioResult = 1;
  82. //    Send( m );
  83. //    if (!async)
  84. //    {
  85. //        while(pb->cntrlParam.ioResult > 0)
  86. //            PushAIPC();
  87. //        return (pb->cntrlParam.ioResult);
  88. //    }
  89. //    else
  90. //        return (noErr);
  91. //}
  92.  
  93. pascal OSErr
  94. ARPBStatus(ParmBlkPtr pb, short async)
  95. {
  96.     struct globals    *g;
  97.     ProcPtr         cmp;
  98.     
  99. #ifdef    DEBUG
  100.     Debugger();
  101. #endif    DEBUG
  102.     g = (struct globals *)(((pb->cntrlParam.ioCRefNum & 0xF000) << 8) +
  103.         (pb->cntrlParam.ioCRefNum & 0x0180) + 0x200);
  104.     pb->cntrlParam.ioResult = 0;
  105.     switch(pb->cntrlParam.csCode)
  106.     {
  107.         case 2:
  108.             pb->cntrlParam.csParam[0] = 0;
  109.             BlockMove( (Ptr)(&(g->sRxCount)), (Ptr)(&(pb->cntrlParam.csParam[1])), 2 );
  110.             break;
  111.         case 8:
  112.             BlockMove( (Ptr)(&(g->asyncErr)), (Ptr)(pb->cntrlParam.csParam), 6 );
  113.             break;
  114.         default:
  115.             pb->cntrlParam.ioResult = -17;
  116.             break;
  117.     }
  118.     if (async)
  119.     {
  120.         cmp = (ProcPtr)StripAddress((Ptr)(pb->ioParam.ioCompletion));
  121.         if (cmp)
  122.             ARComplete( pb, cmp, pb->ioParam.ioResult );
  123.     }
  124.     return (pb->cntrlParam.ioResult);
  125. }
  126.  
  127. pascal OSErr
  128. ARPBWrite(ParmBlkPtr pb, short async)
  129. {
  130.     AROSEmessage    *m;
  131.     struct globals    *g;
  132.     
  133. #ifdef    DEBUG
  134.     Debugger();
  135. #endif    DEBUG
  136.     g = (struct globals *)(((pb->cntrlParam.ioCRefNum & 0xF000) << 8) +
  137.         (pb->cntrlParam.ioCRefNum & 0x0180) + 0x200);
  138.     SetMyTid(g->hisTid);
  139.     m = GetMsg();
  140.     m->mTo = (tid_type)(g->myTid);
  141.     m->mCode = SNBWrite;
  142.     m->mSData[0] = (unsigned long)pb;
  143.     m->mSData[1] = (unsigned long)(pb->ioParam.ioRefNum);
  144.     m->mDataPtr = StripAddress(pb->ioParam.ioBuffer);
  145.     m->mDataSize = pb->ioParam.ioReqCount;
  146.     pb->ioParam.ioResult = 1;
  147.     Send( m );
  148.     if (!async)
  149.     {
  150.         while(pb->ioParam.ioResult > 0)
  151.             PushAIPC();
  152.         return (pb->ioParam.ioResult);
  153.     }
  154.     else
  155.         return (noErr);
  156. }
  157.  
  158. pascal OSErr
  159. ARPBRead(ParmBlkPtr pb, short async)
  160. {
  161.     AROSEmessage    *m;
  162.     struct globals    *g;
  163.     
  164. #ifdef    DEBUG
  165.     Debugger();
  166. #endif    DEBUG
  167.     g = (struct globals *)(((pb->cntrlParam.ioCRefNum & 0xF000) << 8) +
  168.         (pb->cntrlParam.ioCRefNum & 0x0180) + 0x200);
  169.     SetMyTid( g->hisTid );
  170.     m = GetMsg();
  171.     m->mTo = (tid_type)(g->myTid);
  172.     m->mFrom = (tid_type)(g->hisTid);
  173.     m->mCode = SNBRead;
  174.     m->mSData[0] = (unsigned long)pb;
  175.     m->mSData[1] = (unsigned long)(pb->ioParam.ioRefNum);
  176.     m->mDataPtr = StripAddress(pb->ioParam.ioBuffer);
  177.     m->mDataSize = pb->ioParam.ioReqCount;
  178.     pb->ioParam.ioResult = 1;
  179.     Send( m );
  180.     if (!async)
  181.     {
  182.         while(pb->ioParam.ioResult > 0)
  183.             PushAIPC();
  184.         return (pb->ioParam.ioResult);
  185.     }
  186.     else
  187.         return (noErr);
  188. }
  189.  
  190. void
  191. RxComplete(AROSEmessage *m)
  192. {
  193.     ProcPtr     cmp;
  194.     ParmBlkPtr    pb;
  195.     
  196. #ifdef    DEBUG
  197.     Debugger();
  198. #endif    DEBUG
  199.     pb = (ParmBlkPtr)StripAddress((Ptr)(m->mSData[0]));
  200.     cmp = (ProcPtr)StripAddress((Ptr)(pb->ioParam.ioCompletion));
  201.     if ((m->mCode == SNBWrite+1) || (m->mCode == SNBRead+1))
  202.         pb->ioParam.ioActCount = m->mDataSize;
  203.     pb->ioParam.ioResult = m->mStatus;
  204.     FreeMsg( m );
  205.     (void)Receive( 0, 0, 0, 0, RxComplete );
  206.     if (cmp)
  207.         ARComplete( pb, cmp, pb->ioParam.ioResult );
  208. }